@extends('admin.layout.index')
@section('content')
    @include('admin.layout.breadcrumb')
    <div class="wrapper wrapper-content animated fadeInRight" >
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>编辑</h5>
                    </div>
                    <div class="ibox-content">
                        <form id="form"  class="form-horizontal ng-pristine ng-valid" method="post" action="{{ asset('group/edit') }}">
                            <input type="hidden" name="_token" value="{{ csrf_token() }}">
                            <input type="hidden" name="flag" value="1">
                            <input type="hidden" name="group_id" value="{{ $result['admin_group']->group_id }}">
                            <div class="form-group"><label class="col-md-2 control-label required-label">角色名称</label>
                                <div class="col-md-5 col-lg-3"><input id="groupname" name="groupname" type="text" class="form-control required" aria-required="true" value="{{ $result['admin_group']->groupname }}"></div>
                            </div>
                            @if (!empty(count($result['perm'])))
                                    @foreach($result['perm'] as $k => $v)
                            <div class="form-group">
                                <div class="col-md-1 col-lg-1"></div>
                                <div class="col-md-10 col-lg-10">
                                    @if (!empty($v['url']))
                                    <div class="todo-tit-gray">
                                        <div class="checkbox m-l m-r-xs">
                                        <label class="i-checks">                                        
                                        <input type="checkbox" value="{{ $v['url'] }}" name="perm[]" @if (in_array($v['url'],$result['able_perm'])) checked="checked" @endif />                                        
                                        <span class="m-l-xs"><strong>@lang('admin.'.$k)</strong></span>
                                        </label>
                                        </div>
                                    </div>
                                    @else
                                    <div class="todo-tit-gray">
                                        <div class="checkbox m-l m-r-xs">
                                        <label class="i-checks">
                                        <span class="m-l-xs"><strong>@lang('admin.'.$k)</strong></span>
                                        </label>
                                        </div>
                                    </div>                                    
                                    <div class="todo-sub">
                                        @foreach($v as $k2 => $v2)
                                        @if (is_array($v2))
                                        @if (empty($v2['parent']) || $v2['parent'] != '2')
                                        <div class="col-md-2 col-lg-2">
                                            <div class="checkbox m-l m-r-xs">
                                                <label class="i-checks">
                                                <input type="checkbox" value="{{ $v2['url'] }}" name="perm[]" @if (in_array($v2['url'],$result['able_perm'])) checked="checked" @endif />
                                                <span class="m-l-xs">@lang('admin.'.$v2['name'])</span>
                                                </label>
                                            </div>
                                        </div>
                                        @endif
                                        @endif
                                        @endforeach
                                    </div>                                    
                                    @endif
                                    
                                </div>
                                <div class="col-md-1 col-lg-1"></div>
                            </div>
                                @endforeach
                            @endif
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" type="button" id="submitBtn">提交</button>
                                    <a class="btn btn-white" onclick="javascript:history.back()" href="JavaScript:void(0);">返回</a>
                                </div>
                            </div>
                            <!--
                            <div class="actions clearfix">
                                <ul role="menu" aria-label="Pagination">
                                    <li aria-hidden="false"><a href="#finish" role="menuitem">提交</a></li>
                                    <li><a class="btn btn-white" ng-click="javascript:history.back()">返回</a></li>                                                                                
                                </ul>
                            </div>
                            -->
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>


@endsection

@section('css')
<link href="{{ Config::get('website.storage_url') }}/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
@endsection

@section('js')
<!-- iCheck -->
<script src="{{ Config::get('website.storage_url') }}/admin/js/plugins/iCheck/icheck.min.js"></script>
<script src="{{ Config::get('website.storage_url') }}/admin/js/plugins/validate/jquery.validate.min.js"></script>
<script>
    $(document).ready(function(){
        $("#submitBtn").click(function(){
            if($("#form").valid()){
                $("#form").submit();
            }
        });
        
        $('#form').validate({
            errorPlacement: function (error, element)
            {
                element.before(error);
            },
            rules: {
            },
            messages : {
                groupname : {
                    required : "角色名称不能为空"
                }
            }
        });
        
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
    });
</script>
@endsection